package cloud.misiro.spring.cloud.registry;

import cloud.misiro.spring.cloud.MiniDiscoveryProperties;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.serviceregistry.Registration;

import java.net.URI;
import java.util.Map;

public class MiniRegistration implements Registration {

    private final MiniDiscoveryProperties miniDiscoveryProperties;

    public MiniRegistration(MiniDiscoveryProperties miniDiscoveryProperties) {
        this.miniDiscoveryProperties = miniDiscoveryProperties;
    }

    @Override
    public String getServiceId() {
        return miniDiscoveryProperties.getService();
    }

    @Override
    public String getHost() {
        return miniDiscoveryProperties.getIp();
    }

    @Override
    public int getPort() {
        return miniDiscoveryProperties.getPort();
    }

    public void setPort(int port) {
        this.miniDiscoveryProperties.setPort(port);
    }

    @Override
    public boolean isSecure() {
        return miniDiscoveryProperties.isSecure();
    }

    @Override
    public URI getUri() {
        return DefaultServiceInstance.getUri(this);
    }

    @Override
    public Map<String, String> getMetadata() {
        return null;
    }

    public MiniDiscoveryProperties getMiniDiscoveryProperties() {
        return miniDiscoveryProperties;
    }
}
